package cxf.spring.demo.adapter;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.util.Date;
import java.text.SimpleDateFormat;

/**
 * User: Vlad Vinichenko (akerigan@gmail.com)
 * Date: 06.03.2009
 * Time: 21:46:49
 */
public class DateAdapter extends XmlAdapter<String, Date> {

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");

    public Date unmarshal(String v) throws Exception {
        if (v == null) {
            return null;
        } else {
            return dateFormat.parse(v);
        }
    }

    public String marshal(Date v) throws Exception {
        if (v == null) {
            return null;
        } else {
            return dateFormat.format(v);
        }
    }
}
